package com.zwan.oam_rtc.utils.messages;

import java.nio.ByteBuffer;

import com.zwan.oam_rtc.utils.wintcp.ByteTransfer;


public class CallMessage extends AbstractStruct {
    
//    DWORD dwFunctionType    1_webcall
//    DWORD dwSubType 0_webcall calling 
//    Char String1[30]    Callingnumber (����_���з��𷽺���)
//    Char String2[30]    Callednumber(����_���н��շ�����)
//    Char String3[30]    Callflowid (������Ŵ� ������ʱΪ��)
//    DWORD dwtmp1    �ݲ�ʹ��
//    char strtmp2[40]    �ݲ�ʹ��
//    DWORD dwtmp3    �ݲ�ʹ��
    private int dwFunction = 1;
    private int dwSubType = 0;
    private byte[] calling = new byte[30];
    private byte[] called = new byte[30];
    private byte[] flowid = new byte[30];
    private int dwtmp1;
    private byte[] strtmp2 = new byte[40];
    private int dwtmp3;
    private static int LENGTH = 176;
    
    public static final int CALLING_FLAG = 0;
    public static final int CALLED_FLAG = 1;
    
    @Override
    public void writeToBuffer(ByteBuffer bf) {
        bf.putInt(dwFunction);
        bf.putInt(dwSubType);
        bf.put(calling);
        bf.put(called);
        bf.put(flowid);
        bf.putInt(dwtmp1);
        bf.put(strtmp2);
        bf.putInt(dwtmp3);
    }

    @Override
    public void readFromBuffer(ByteBuffer bf) {
        dwFunction = bf.getInt();
        dwSubType = bf.getInt();
        bf.get(calling);
        bf.get(called);
        bf.get(flowid);
        dwtmp1 = bf.getInt();
        bf.get(strtmp2);
        dwtmp3 = bf.getInt();
    }

    @Override
    public int getLength() {
        return LENGTH;
    }

    public int getDwFunction() {
        return dwFunction;
    }

    public void setDwFunction(int dwFunction) {
        this.dwFunction = dwFunction;
    }

    public int getDwSubType() {
        return dwSubType;
    }

    public void setDwSubType(int dwSubType) {
        this.dwSubType = dwSubType;
    }

    public String getCalling() {
        return ByteTransfer.getString(calling);
    }

    public void setCalling(String calling) {
        ByteTransfer.str2Byte(calling, this.calling);
    }

    public String getCalled() {
        return ByteTransfer.getString(called);
    }

    public void setCalled(String called) {
        ByteTransfer.str2Byte(called, this.called);
    }

    public String getFlowid() {
        return ByteTransfer.getString(flowid);
    }

    public void setFlowid(String flowid) {
        ByteTransfer.str2Byte(flowid, this.flowid);
    }

    public int getUserId(){
        return getDwtmp1();
    }
    
    public String getUserName(){
        return getStrtmp2();
    }
    
    public int getDwtmp1() {
        return dwtmp1;
    }

    public void setDwtmp1(int dwtmp1) {
        this.dwtmp1 = dwtmp1;
    }

    public String getStrtmp2() {
        return ByteTransfer.getString(strtmp2);
    }

    public void setStrtmp2(byte[] strtmp2) {
        System.arraycopy(strtmp2, 0, this.strtmp2, 0, Math.min(strtmp2.length, this.strtmp2.length));
    }

    public int getDwtmp3() {
        return dwtmp3;
    }

    public void setDwtmp3(int dwtmp3) {
        this.dwtmp3 = dwtmp3;
    }

}
